package com.sihan.framework.etm.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.framework.model.BaseModel;
import com.framework.model.UserDetail;
import com.framework.mybatis.annotation.AutoGenerator;
import com.framework.mybatis.enums.IdType;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.*;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 用户表
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table(name = "jdx_user")
public class User extends BaseModel implements UserDetail, Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 用户ID
	 */
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	@AutoGenerator(idType = IdType.UUID32)
	private String id;

	private String code;

	/**
	 * 用户昵称
	 */
	private String name;

	/**
	 * 用户名
	 */
	private String username;

	/**
	 * 电话号码
	 */
	private String phone;

	/**
	 * 电子邮箱
	 */
	private String email;

	/**
	 * 密码
	 */
	@JsonIgnore
	private String password;

	/**
	 * 盐
	 */
	@JsonIgnore
	private String salt;

	/**
	 * 性别: true --> 男 false -->女
	 */
	private Boolean sex;

	/**
	 * 是否被锁定：0 没有被锁定；1被锁定；默认为0
	 */
	private Boolean locked;

	@JsonIgnore
	private Boolean isDelete;

	/**
	 * 24小时内连续登陆失败次数，每天0点清0，登陆成功后清0
	 */
	private Integer loginFault;

	/**
	 * 锁定起始时间
	 */
	private Date lockTime;

	/**
	 * 上次修改密码时间
	 */
	private Date updatePsdTime;

	/**
	 * 用户状态，-1：注销，0：激活，1：休眠
	 */
	private Integer state;

	/**
	 * 开始休眠时间（只对处于休眠状态用户有用）
	 */
	private Date sleepTime;

	/**
	 * 用户类型， 0：长期账号，1：临时账号
	 */
	private Integer userType;

	/**
	 * 最后访问时间
	 */
	private Date lastAccessTime;

	/**
	 * 绑定客户端访问IP
	 */
	private String loginIp;

	/**
	 * 公司编号
	 */
	private String companyCode;

	/**
	 * 公司名称
	 */
	private String orgName;

	/**
	 * 访问起始时间
	 */
	private Date accessStartTime;

	/**
	 * 访问结束时间
	 */
	private Date accessEndTime;

	/**
	 * 是否是初始化用户 1：是，0：否
	 */
	private Boolean defaulted;

	/**
	 * 是否有手动激活
	 */
	private Boolean hasActive;

	private String orgId;

	private String icCard;

	private String faceImgs;

	private String avator;

	private String position;

	public User(String username, Boolean isDelete) {
		this.username = username;
		this.isDelete = isDelete;
	}

	public User(String username, String password, String salt, String name, Boolean sex) {
		this.username = username;
		this.password = password;
		this.salt = salt;
		this.name = name;
		this.sex = sex;
	}

	public User(String id,String userName,Boolean isDelete) {
		this.id = id;
		this.isDelete = isDelete;
	}

	public User(String username) {
		this.username = username;
	}


    @Override
	public Long getUserId() {
		return null;
	}

}
